package com.chen.exception;



import com.chen.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class IOTWebExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    public Result exceptionHandler(Exception e){
        log.error("",e);
        if (e instanceof DuplicateKeyException){
            return Result.success("索引重复");
        }
        else {
            return Result.success(e.toString());
        }
    }
}

